package cn.tedu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/*
* 循环,批量插入数据
* */
public class Demo06 {
    public static void main(String[] args) {
        try (Connection conn = DBUtils.getConn();)
        {
            String sql = "insert into user values(null,?,?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            for (int i = 1; i <= 100; i++) {
                ps.setString(1,"name"+i);
                ps.setString(2,"pw"+i);
                ps.addBatch();
                if(i%20==0){
                    ps.executeUpdate();
                }
            }
            ps.executeUpdate();
            System.out.println("操作完成");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
